package com.example.myonlinemusic.config;

import com.example.myonlinemusic.tools.Constant;
import com.example.myonlinemusic.tools.ResponseBodyMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//配置一个拦截器
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    //重写这个方法
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession httpSession = request.getSession(false);
        if(httpSession != null && httpSession.getAttribute(Constant.USERINFO_SESSION_KEY) != null) {

            return true;
        }
        return false;
    }
}
